package com.wiloon.java8x.io.file.loganalyzer;

import java.io.*;

/**
 * Created by USER on 2015/8/14.
 */
public class TextFilter {
    public void filterTextFile(String source, String target, String key) {
        File fileOut = new File(target);

        try {
            FileInputStream fis = new FileInputStream(source);
            InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            FileOutputStream fos = new FileOutputStream(target);
            OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");

            while ((line = br.readLine()) != null) {
                String tmp = line;
                if (line.contains(key)) {
                    osw.write(line);
                    osw.write("\r\n");

                }
            }
            osw.flush();
            osw.close();

        } catch (Exception e) {

        } finally {

        }

    }
}
